﻿using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;

namespace ZRT.RHPX.Core
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class DBContext : Database
    {
        #region 构造函数

        private DBContext()
            : base("ConnString")
        {
        }

        #endregion

        /// <summary>
        /// 获取实例
        /// </summary>
        /// <returns></returns>
        public static DBContext GetInstance()
        {
            DBContext Instance = CallContext.GetData("DBContextKey") as DBContext;

            if (Instance == null)
            {
                Instance = new DBContext();
                CallContext.SetData("DBContextKey", Instance);
            }

            return Instance;

        }

        /// <summary>
        /// 开启事务
        /// </summary>
        /// <returns></returns>
        public static ITransaction OpenTransaction()
        {
            return DBContext.GetInstance().GetTransaction();
        }
    }
}
